#include <iostream>
#include <grpcpp/grpcpp.h>

#include "calculator.pb.h"
#include "calculator.grpc.pb.h"

using namespace std;
using grpc::Channel;
using grpc::ClientContext;
using grpc::Status;
using test::Params;
using test::Result;
using test::Calculator;

class CalculatorClient {
 public:
  CalculatorClient(std::shared_ptr<Channel> channel)
      : stub_(Calculator::NewStub(channel)) {}

  void Add(double a, double b) {
      Params params;
      params.set_a(a);
      params.set_b(b);

      Result result;
      ClientContext context;

      Status status = stub_->Add(&context, params, &result);
      cout << result.result() << endl;

  }
  void Subtract(double a, double b){
      Params params;
      params.set_a(a);
      params.set_b(b);

      Result result;
      ClientContext context;

      Status status = stub_->Subtract(&context, params, &result);
      cout << result.result() << endl;
  }
  void Multiply(double a, double b) {
      Params params;
      params.set_a(a);
      params.set_b(b);

      Result result;
      ClientContext context;

      Status status = stub_->Multiply(&context, params, &result);
      cout << result.result() << endl;
  }
  void Divide(double a, double b) {
      Params params;
      params.set_a(a);
      params.set_b(b);

      Result result;
      ClientContext context;

      Status status = stub_->Divide(&context, params, &result);
      cout << result.result() << endl;
  }
 private:
  std::unique_ptr<Calculator::Stub> stub_;
};

int main() {

  CalculatorClient client(grpc::CreateChannel(
      "localhost:50051", grpc::InsecureChannelCredentials()));

  client.Add(1, 1);
  client.Subtract(2,1);
  client.Multiply(3,2);
  client.Divide(6,2);

  return 0;
}
